package androids.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import androids.excepcion.DAOExcepcion;
import androids.negocio.ProductoNegocio;

/**
 * Servlet implementation class RegistrarProductoServlet
 */
@WebServlet("/RegistrarProductoServlet")
public class RegistrarProductoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarProductoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String nombre = request.getParameter("nombre");
		String precio = request.getParameter("precio");
		String stock = request.getParameter("stock");
		String numserie = request.getParameter("numserie");
		String idproducto = request.getParameter("idproducto");
		String id_cat = request.getParameter("idcategoria");
		String id_prov = request.getParameter("idproveedor");
		
		System.out.println("PRODUCTO INGRESADO");
		System.out.println(nombre);
		System.out.println(precio);
		System.out.println(stock);
		System.out.println(numserie);
		System.out.println(id_cat);
		System.out.println(id_prov);
		
		//Llamamos a la clase negocio
		ProductoNegocio neg = new ProductoNegocio();
		
		try{
			neg.insertarProducto(id_cat, id_prov, nombre, stock, precio, numserie);
			RequestDispatcher rd = request.getRequestDispatcher("/producto_registrar.jsp");
			rd.forward(request, response);
		}catch(DAOExcepcion e){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
			
		}
		
		
	}

}
